package com.masterclient.app.modules.firstpager.fragments.adapters;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.view.ViewGroup;

import com.eoner.baselibrary.bean.firstpager.NewGoodDiscountBean;

import java.util.List;

/**
 * 作者：sean
 * 创建时间：2017/8/15 14:51
 * 功能说明：
 */

public class NewGoodsSubPagerAdapter extends FragmentStatePagerAdapter{

    private List<Fragment> list;
    List<NewGoodDiscountBean.DataBean.ShTypesBean> sh_types;
    public NewGoodsSubPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    public void setSh_types(List<NewGoodDiscountBean.DataBean.ShTypesBean> sh_types) {
        this.sh_types = sh_types;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return sh_types.get(position).getSh_name();
    }

    private int mChildCount = 0;

    @Override
    public void notifyDataSetChanged() {
        mChildCount = getCount();
        super.notifyDataSetChanged();
    }
    @Override
    public int getItemPosition(Object object)   {
        if ( mChildCount > 0) {
            mChildCount --;
            return POSITION_NONE;
        }
        return super.getItemPosition(object);
    }

    public void setList(List<Fragment> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list==null?0:list.size();
    }

    @Override
    public Fragment getItem(int arg0) {
        return list.get(arg0);
    }
    @Override
    public Object instantiateItem(ViewGroup arg0, int arg1) {

        return super.instantiateItem(arg0, arg1);
    }
    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        super.destroyItem(container, position, object);
    }
}
